package treeSet;

import java.util.*;

public class Item implements Comparable<Item> {
    
    private String description;
    private int partNumber;

    public Item(String description, int partNumber) {
        this.description = description;
        this.partNumber = partNumber;
    }

    public String getDescription() {
        return description;
    }

    public String toString() {
        return "[description=" + description 
            + ", partNumber=" + partNumber + "]";
    }

    public boolean equals(Object other) {
        if (this == other) return true;
        if (other == null) return false;
        if (getClass() != other.getClass()) return false;
        var o = (Item)other;
        return Objects.equals(description, o.description)
            && partNumber == o.partNumber;
    }

    public int hashCode() {
        return Objects.hash(description, partNumber);
    }

    public int compareTo(Item other) {
        int diff = Integer.compare(partNumber, other.partNumber);
        return diff != 0 ? diff : 
            description.compareTo(other.description);
    }

}
